package com.xiaoze.question.controller;

import java.util.List;

import com.xiaoze.common.core.domain.entity.SysDept;
import com.xiaoze.question.dto.QuestionAnswerUserInput;
import com.xiaoze.question.dto.QuestionScenarioListOutput;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.xiaoze.common.annotation.Log;
import com.xiaoze.common.core.controller.BaseController;
import com.xiaoze.common.core.domain.AjaxResult;
import com.xiaoze.common.enums.BusinessType;
import com.xiaoze.question.domain.QuestionScenario;
import com.xiaoze.question.service.IQuestionScenarioService;
import com.xiaoze.common.utils.poi.ExcelUtil;
import com.xiaoze.common.core.page.TableDataInfo;

/**
 * 业务场景管理Controller
 *
 * @author 胡昊泽
 * @date 2024-08-02
 */
@RestController
@RequestMapping("/question/scenario")
public class QuestionScenarioController extends BaseController {
    @Autowired
    private IQuestionScenarioService questionScenarioService;

    /**
     * 查询业务场景管理列表
     */
    @PreAuthorize("@ss.hasPermi('question:scenario:list')")
    @GetMapping("/list")
    public TableDataInfo list(QuestionScenario questionScenario) {
        startPage();
        List<QuestionScenarioListOutput> list = questionScenarioService.selectQuestionScenarioList(questionScenario);
        return getDataTable(list);
    }

    /**
     * 导出业务场景管理列表
     */
    @PreAuthorize("@ss.hasPermi('question:scenario:export')")
    @Log(title = "业务场景管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(QuestionScenario questionScenario) {
        List<QuestionScenarioListOutput> list = questionScenarioService.selectQuestionScenarioList(questionScenario);
        ExcelUtil<QuestionScenarioListOutput> util = new ExcelUtil<>(QuestionScenarioListOutput.class);
        return util.exportExcel(list, "scenario");
    }

    /**
     * 获取业务场景管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('question:scenario:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(questionScenarioService.selectQuestionScenarioById(id));
    }


    @PreAuthorize("@ss.hasPermi('question:scenario:queryUser')")
    @GetMapping(value = "queryForUser")
    public AjaxResult getInfo(QuestionAnswerUserInput questionAnswerUserInput) {
        return AjaxResult.success(questionScenarioService.selectQuestionScenarioForUser(questionAnswerUserInput));
    }

    /**
     * 获取业务场景管理下拉树列表
     */
    @GetMapping("/treeselect")
    public AjaxResult treeselect(QuestionScenario questionScenario) {
        return AjaxResult.success(questionScenarioService.selectQuestionScenarioTreeList(questionScenario));
    }

    /**
     * 新增业务场景管理
     */
    @PreAuthorize("@ss.hasPermi('question:scenario:add')")
    @Log(title = "业务场景管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody QuestionScenario questionScenario) {
        return toAjax(questionScenarioService.insertQuestionScenario(questionScenario));
    }

    /**
     * 修改业务场景管理
     */
    @PreAuthorize("@ss.hasPermi('question:scenario:edit')")
    @Log(title = "业务场景管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody QuestionScenario questionScenario) {
        return toAjax(questionScenarioService.updateQuestionScenario(questionScenario));
    }

    /**
     * 删除业务场景管理
     */
    @PreAuthorize("@ss.hasPermi('question:scenario:remove')")
    @Log(title = "业务场景管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(questionScenarioService.deleteQuestionScenarioByIds(ids));
    }
}
